package com.xiao.stack;

/**
 * @CreateBy 花和尚  1130365579@qq.com  2022/11/12 14:47
 * @Version 1.0
 */
public class JVMStackOOM {

    // 死循环
    private void dontStop() {
        while (true) {
        }
    }

    public void stackLeakByThread() {
        // 不断的创建线程   执行一个永远不会停下来的函数
        while (true) {
            Thread thread = new Thread(
                    this::dontStop
            );
            thread.start();
        }
    }

    /**
     * 运行会导致操作系统假死
     *
     * @param args
     */
    public static void main(String[] args) {
        JVMStackOOM jvmStackOOM = new JVMStackOOM();
        jvmStackOOM.stackLeakByThread();
    }
}
